package org.lmind.example.util.common;

import static org.junit.Assert.*;

import java.util.Enumeration;

import org.junit.Test;
import org.lmind.example.util.common.PlaceholderResolver.Placeholder;
import org.lmind.example.util.common.PlaceholderResolver.Resolver;

public class PlaceholderResolverTestCase {
	
	@Test
	public void test() {
		PlaceholderResolver pr = new PlaceholderResolver("${", "}");
		Resolver r = pr.resolver("The ${user.name} send a mail ${user.mail} !");
		Enumeration<Placeholder> emu = r;
		while (emu.hasMoreElements()) {
			Placeholder item = emu.nextElement();
			if (item.getKey().equals("user.name")) {
				item.replace("mian.liu");
			} else if (item.getKey().equals("user.mail")) {
				item.replace("mian.liu@yeepay.com");
			}
		}
		emu.nextElement();
		String ret = r.build();
		assertEquals(ret, "The mian.liu send a mail mian.liu@yeepay.com !");
	}

	@Test
	public void test2() {
		PlaceholderResolver pr = new PlaceholderResolver("${", "}");
		Resolver r = pr.resolver("The ${user.name} send a mail ${user.mail} !");
		Enumeration<Placeholder> emu = r;
		while (emu.hasMoreElements()) {
			Placeholder item = emu.nextElement();
			if (item.getKey().equals("user.name")) {
				item.replace("mian.liu");
			} else if (item.getKey().equals("user.mail")) {
				item.replace("mian.liu@yeepay.com");
			}
			break;
		}
		String ret = r.build();
		assertEquals(ret, "The mian.liu send a mail ${user.mail} !");
	}
}
